package com.enlorenz.support.bank.iso8583;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.enlorenz.core.annotation.Property;
import com.enlorenz.core.annotation.util.AnnotationUtils;
import com.enlorenz.core.annotation.util.AnnotationUtils.PropAnnoWrapper;

/**
 * Iso配置
 * @author Karma
 *
 */
public class IsoConfig {
	//iso配置列表
	private List<PropAnnoWrapper<IsoProperty>> isoPropList;
	//属性map
	private Map<String,PropAnnoWrapper<Property>> propertyMap;
	//域索引包装类
	private Map<Integer,IsoWrapper> indexIsoWrapperMap;
	//域索引包装类列表
	private List<IsoWrapper> isoWrapperList;
	
	@SuppressWarnings("rawtypes")
	public IsoConfig(Class claxx){
		isoPropList=AnnotationUtils.getAnnoList(claxx,IsoProperty.class);
		propertyMap=AnnotationUtils.getAnnoMap(claxx, Property.class);
		indexIsoWrapperMap=new HashMap<Integer,IsoWrapper>();
		
		isoWrapperList=new ArrayList<IsoWrapper>(isoPropList.size());
		for(PropAnnoWrapper<IsoProperty> paw:isoPropList){
			if(null == paw.getAnnoObject()){
				continue;
			}
			IsoWrapper iw=new IsoWrapper();
			iw.setFieldName(paw.getFieldName());
			iw.setIsoProperty(paw.getAnnoObject());
			iw.setProperty(propertyMap.get(paw.getFieldName())
					.getAnnoObject());
			iw.setIndex(paw.getAnnoObject().index());
			
			isoWrapperList.add(iw);
			indexIsoWrapperMap.put(paw.getAnnoObject().index(), iw);
		}
	}
	
	/**
	 * 通过域索引获取属性对象封装类
	 * @param index 域索引
	 * @return 属性对象
	 */
	public IsoWrapper getIsoWrapperByIndex(int index){
		return indexIsoWrapperMap.get(index);
	}
	
	/**
	 * 通过域索引获取属性对象
	 * @param index 域索引
	 * @return 属性对象
	 */
	public IsoProperty getIsoPropertyByIndex(int index){
		return indexIsoWrapperMap.get(index).getIsoProperty();
	}
	
	/**
	 * 通过域索引获取属性对象
	 * @param index 域索引
	 * @return 属性对象
	 */
	public Property getPropertyByIndex(int index){
		return indexIsoWrapperMap.get(index).getProperty();
	}
	
	
	public List<PropAnnoWrapper<IsoProperty>> getIsoPropList() {
		return isoPropList;
	}


	public void setIsoPropList(List<PropAnnoWrapper<IsoProperty>> isoPropList) {
		this.isoPropList = isoPropList;
	}


	public Map<String, PropAnnoWrapper<Property>> getPropertyMap() {
		return propertyMap;
	}


	public void setPropertyMap(Map<String, PropAnnoWrapper<Property>> propertyMap) {
		this.propertyMap = propertyMap;
	}

	public Map<Integer, IsoWrapper> getIndexIsoWrapperMap() {
		return indexIsoWrapperMap;
	}

	public List<IsoWrapper> getIsoWrapperList() {
		return isoWrapperList;
	}
	
}
